package com.apply.repository;

import com.apply.entity.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @author tianp
 */
public interface UserRepository extends JpaRepository<SysUser, Long>, JpaSpecificationExecutor<SysUser> {
    /**
     * 根据邮箱修改密码
     *
     * @param password
     * @param username
     * @return
     */
    @Modifying(clearAutomatically = true)
    @Query("update SysUser set password = ?1 where username = ?2")
    public int updatePassowrd(String password, String username);

    /**
     * 根据用户名查找用户
     *
     * @param username
     * @param roleId
     * @return
     */
    public SysUser findByUsernameAndRoleId(String username, Integer roleId);

    /**
     * 根据id更新
     *
     * @return
     */
    @Modifying(clearAutomatically = true)
    @Query("update SysUser as u set u.photoPath = ?1 where u.id = ?2")
    public int updateUser(String photoPath, Long id);
}
